﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SimpleTaskManager.Domain.Abstract;
using SimpleTaskManager.WebUI.Models;

namespace SimpleTaskManager.WebUI.Controllers
{
    /// <summary>
    /// Controller responsible for getting the basic info about the company
    /// </summary>
    public class InfoController : Controller
    {
        private IUserRepository userRep;
        private IProjectRepository projectRep;
        private ITaskRepository taskRep;

        /// <summary>
        /// Creates an instance of the information controller.
        /// </summary>
        /// <param name="userRepository">A repository containing the users.</param>
        /// <param name="projectRepository">A repository containing the projects.</param>
        /// <param name="taskRepository">A repository containing the tasks.</param>
        public InfoController(IUserRepository userRepository, IProjectRepository projectRepository, ITaskRepository taskRepository)
        {
            userRep = userRepository;
            projectRep = projectRepository;
            taskRep = taskRepository;
        }

        //
        // GET: /Info/
        /// <summary>
        /// Returns a view with general information about the company.
        /// </summary>
        /// <returns>The rendered view.</returns>
        public ActionResult Index()
        {
            return View("GeneralInfo");
        }

        /// <summary>
        /// Returns partial view with some basic description of the company - static text
        /// </summary>
        /// <returns>Partial View with company description</returns>
        public PartialViewResult WhatWeDo()
        {
            return PartialView();
        }

        /// <summary>
        /// Renders PartialView with some basic data about the company, like: number of employees, number of current projects,
        /// number of finished projects, number of employees on each positions, what tasks are currently run and so on. 
        /// </summary>
        /// <returns>Partial View with basic data about the company</returns>
        /*
         * Number of currently hired employees
         * Number of employees on a leave
         * Number of current projects
         * Number of current tasks
         * Number of employees on each position - maybe a pie chart representing the ratio of each position to the whole number of employees
         * Pie chart with projects finished on time / not on time
         * Column chart showing how many employees work on each project - to see easily which project is the most employee-consuming
         * 
         */
        public PartialViewResult Employees()
        {
            SearchResultModel result = new SearchResultModel();
            result.Users = userRep.Users.ToList();
            result.Projects = projectRep.Projects.ToList();
            result.Tasks = taskRep.Tasks.ToList();
            return PartialView(result);
        }

        /// <summary>
        /// Renders PartialView with bar chart indicating how many employees work on each project
        /// </summary>
        /// <returns>Partial View with bar chart</returns>
        [Authorize]
        public PartialViewResult EmployeesInProjects()
        {
            return PartialView(projectRep.Projects);
        }


        /// <summary>
        /// Renders partial view with chart showing how many people are on specific position
        /// </summary>
        /// <returns>Partial View with chart</returns>
        [Authorize]
        public PartialViewResult ChartEmployeesPositions()
        {
            return PartialView(userRep.Users);
        }
    }
}
